#
# @lc app=leetcode.cn id=1 lang=python3
#
# [1] 两数之和
#

# @lc code=start
class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        left = 0
        right = len(nums) - 1

        copy = nums.copy()
        nums.sort()

        while left < right:
            sum = nums[left] + nums[right]
            if sum == target:
                break
            elif sum < target:
                left = left + 1
            elif sum > target:
                right = right - 1

        res = []

        for i in range(len(nums)):
            if copy[i] == nums[left] or copy[i] == nums[right]:
                res.append(i)
        return res
# @lc code=end
